import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/tm/positionReq/list',
  save='/tm/positionReq/add',
  edit='/tm/positionReq/edit',
  deleteOne = '/tm/positionReq/delete',
  deleteBatch = '/tm/positionReq/deleteBatch',
  importExcel = '/tm/positionReq/importExcel',
  exportXls = '/tm/positionReq/exportXls',
  publishOne = '/tm/positionReq/publish',
  batchPublish = '/tm/positionReq/publishBatch',
  stopOne = '/tm/positionReq/stop',
  batchStop = '/tm/positionReq/stopBatch',
  offReqUrl = '/tm/positionReq/off',
  batchOffReqUrl = '/tm/positionReq/offBatch',
  restart = '/tm/positionReq/restart',
  checkRestartUrl = '/tm/positionReq/check/restart/',
  queryLockResumeList = '/tm/positionReq/queryLockResumeListByMainId',
  userInfoUrl = '/sys/user/queryByUserName/',
  verifyCopyUrl = '/tm/positionReq/verify/copy/'
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

export const verifyCopy = (params) => defHttp.get({ url: Api.verifyCopyUrl+params });
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 查询锁定需求表数据
 * @param params
 */
export const queryLockResumeListByMainId = (id) => defHttp.get({url: Api.queryLockResumeList, params:{ id }});


export const getUserInfo = (params) => defHttp.get({ url: Api.userInfoUrl+params });
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
/**
 * 发布需求
 * @param params
 * @param handleSuccess
 */
export const publish = (params,handleSuccess) => {
  console.log('发布需求 publish...')
  return defHttp.post({url: Api.publishOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量发布需求
 * @param params
 * @param handleSuccess
 */
export const batchPublish = (params,handleSuccess) => {
  return defHttp.post({url: Api.batchPublish, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 停止发布需求
 * @param params
 * @param handleSuccess
 */
export const stop = (params,handleSuccess) => {
  return defHttp.post({url: Api.stopOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量停止发布需求
 * @param params
 * @param handleSuccess
 */
export const batchStop = (params,handleSuccess) => {
  return defHttp.post({url: Api.batchStop, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 停止发布需求
 * @param params
 * @param handleSuccess
 */
export const offReq = (params,handleSuccess) => {
  return defHttp.post({url: Api.offReqUrl, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量停止发布需求
 * @param params
 * @param handleSuccess
 */
export const batchOffReq = (params,handleSuccess) => {
  return defHttp.post({url: Api.batchOffReqUrl, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}



/**
 * 重启
 * @param paramexport const checkRestart = (params, isUpdate) => {
  return defHttp.post({ url: Api.checkRestartUrl, params }, { isTransformResponse: false });
}s
 * @param isUpdate
 */
export const restart = (params, isUpdate) => {
  return defHttp.post({ url: Api.restart, params }, { isTransformResponse: false });
}

// export const checkRestart = (params,handleSuccess) => {
//   return defHttp.delete({url: Api.checkRestartUrl, params}, {joinParamsToUrl: true}).then(() => {
//     handleSuccess();
//   });
// }

export const checkRestart = (params) => defHttp.get({ url: Api.checkRestartUrl+params });